#include "widget.h"
#include "server.h"

#include <QApplication>

FILE* output = nullptr;

void msgHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg) {
    (void) type;
    (void) context;
    const QByteArray& log = msg.toUtf8();
    fprintf(output, "%s\n", log.constData());
    fflush(output);		// 确保数据落入硬盘
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    output = fopen("./log.txt", "a");
    qInstallMessageHandler(msgHandler);

    Widget w;
    w.show();

    HttpServer* server = HttpServer::getInstance();
    if(!server->init()) {
        qDebug() << "服务器启动失败!";
    } else {
        qDebug() << "服务器启动成功!";
    }

    WebsocketServer* webSocketServer = WebsocketServer::getInstance();
    webSocketServer->init();
    return a.exec();
}
